package pers.qianyu.month_202012.date_20201203;

import java.util.*;

/**
 * 45. 跳跃游戏 II
 * https://leetcode-cn.com/problems/jump-game-ii/
 *
 * @author mizzle rain
 * @date 2020-12-03 23:41
 */
public class Jump {
    /**
     * 动态规划超时
     */
    public int jump(int[] nums) {
        if (nums == null) {
            return -1;
        }
        if (nums.length <= 1) {
            return 0;
        }
        int[] dp = new int[nums.length];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for (int i = 1; i < dp.length; i++) {
            for (int k = 0; k < i; k++) {
                if (k + nums[k] >= i) {
                    dp[i] = Math.min(dp[i], dp[k] + 1);
                }
            }
        }
        return dp[dp.length - 1];
    }
}
